<template>
	<el-form ref="formRef" :model="formData" label-width="150px" v-loading="loading">
        <el-form-item label="图标：" prop="web_logo">
            <div class="w-80">
                <imageUpload v-model="formData.icon" promptText="建议尺寸：200*200" :limit="1" />
            </div>
        </el-form-item>
		<el-form-item label="状态：">
			<div>
				<el-radio-group v-model="formData.status">
					<el-radio :label="1">开启</el-radio>
					<el-radio :label="0">关闭</el-radio>
				</el-radio-group>
				<div class="el-form-tips">请选择余额支付开启或关闭，关闭时用户端不显示</div>
			</div>
		</el-form-item>
	</el-form>
	<footerSubmit>
		<el-button v-auth="'setting/pay/edit'" type="primary" @click="handleSubmit">保存</el-button>
	</footerSubmit>
</template>

<script lang="ts" setup name="payCashEdit">
import { ref, reactive, onMounted } from 'vue';
import { payDetail,payEdit } from '/@/api/setting/pay';
import { messageSuccess } from '/@/utils/message';

const formRef = ref(null);

const loading = ref(true);

const identify = 'cash';

// 表单数据
const formData = reactive({
    identify: identify,
	icon: '',
	status: '',
});

// 获取数据
const getData = async () => {
	const data = await payDetail({identify:identify});

	for (const key in formData) {
		if (data[key] != null && data[key] != undefined) {
			formData[key] = data[key];
		}
	}
	loading.value = false;
};

// 保存提交
const handleSubmit = async () => {
	await payEdit(formData);
	messageSuccess('设置成功');
	getData();
};

onMounted(() => {
	getData();
});
</script>
